# Maintainer: Timo Teräs <timo.teras@iki.fi>
pkgname=hunspell-en
pkgver=2020.12.07
pkgrel=4
pkgdesc="English hunspell dictionaries"
url="http://wordlist.aspell.net/dicts/"
arch="noarch"
license="custom"
subpackages="$pkgname-doc"
options="!check !spdx" # data only package
source="https://downloads.sourceforge.net/project/wordlist/speller/$pkgver/hunspell-en_US-$pkgver.zip
	https://downloads.sourceforge.net/project/wordlist/speller/$pkgver/hunspell-en_CA-$pkgver.zip
	https://downloads.sourceforge.net/project/wordlist/speller/$pkgver/hunspell-en_AU-$pkgver.zip
	https://downloads.sourceforge.net/project/wordlist/speller/$pkgver/hunspell-en_GB-large-$pkgver.zip
	apostrophe.patch
	"
builddir="$srcdir"

_languages="en_ag en_au en_bs en_bw en_bz en_ca en_dk en_gb en_gh en_hk en_ie en_in en_jm en_na en_ng en_nz en_ph en_sg en_tt en_us en_za en_zw"
for _language in $_languages; do
	_subpkgname=$pkgname-${_language##en_}

	depends="$depends $_subpkgname=$pkgver-r$pkgrel"
	subpackages="$subpackages $_subpkgname:_split_langs"
done

package() {
	install -dm755 "$pkgdir"/usr/share/hunspell
	install -m644 en_*.dic en_*.aff "$pkgdir"/usr/share/hunspell

	local lang
	for lang in en_AG en_BS en_BW en_BZ en_DK en_GB en_GH en_HK en_IE en_IN en_JM en_NA en_NG en_NZ en_SG en_TT en_ZA en_ZW; do
		ln -svf en_GB-large.aff "$pkgdir"/usr/share/hunspell/$lang.aff
		ln -svf en_GB-large.dic "$pkgdir"/usr/share/hunspell/$lang.dic
	done
	# shellcheck disable=2043
	for lang in en_PH; do
		ln -svf en_US.aff "$pkgdir"/usr/share/hunspell/$lang.aff
		ln -svf en_US.dic "$pkgdir"/usr/share/hunspell/$lang.dic
	done

	# docs
	install -dm755 "$pkgdir"/usr/share/doc/$pkgname
	install -m644 README_en_*.txt "$pkgdir"/usr/share/doc/$pkgname

	# licenses
	install -D -m644 README_en_US.txt "$pkgdir"/usr/share/licenses/$pkgname/Copyright_en_US
	install -D -m644 README_en_CA.txt "$pkgdir"/usr/share/licenses/$pkgname/Copyright_en_CA
	install -D -m644 README_en_GB-large.txt "$pkgdir"/usr/share/licenses/$pkgname/Copyright_en_GB-large
}

_split_langs() {
	_variant=$(echo ${subpkgname#"$pkgname"-} | tr '[:lower:]' '[:upper:]')

	depends=""
	pkgdesc="English hunspell dictionaries ($_variant only)"

	amove "usr/share/hunspell/en_$_variant*.aff"
	amove "usr/share/hunspell/en_$_variant*.dic"

	if [ -f "$pkgdir"/usr/share/licenses/$pkgname/Copyright_en_$_variant ]; then
		amove usr/share/licenses/$pkgname/Copyright_en_$_variant
	fi
	if [ -f "$pkgdir"/usr/share/licenses/$pkgname/Copyright_en_$_variant-large ]; then
		amove usr/share/licenses/$pkgname/Copyright_en_$_variant-large
	fi
	if [ -f "$pkgdir"/usr/share/doc/hunspell-en/README_en_$_variant.txt ]; then
		amove usr/share/doc/hunspell-en/README_en_$_variant.txt
	fi
	if [ -f "$pkgdir"/usr/share/doc/hunspell-en/README_en_$_variant-large.txt ]; then
		amove usr/share/doc/hunspell-en/README_en_$_variant-large.txt
	fi
}

sha512sums="
a35ff630883e2410164e21669e6a46d15c73c76d969829cbf20903949dc7815886c0907f192aad9d363f777dcc9acfbd1e60c8175fbebf14d551e1d6e524c075  hunspell-en_US-2020.12.07.zip
6e34bddbc1f8fd37c4b57d4520cd89a1f301430e7202cc35b0918ca856ff3eaba00743ef904a8b89f806812729976169826857a0fa2f452dd0ed922eeb6a9303  hunspell-en_CA-2020.12.07.zip
626ea0f54e6203e9824cf2473d72e3e395966bf295adeef7cc02a83b2a20c30af1b1241384eb919f72fc8ee6c36cc351a754453004ec55c0e5f8168d2cd45da2  hunspell-en_AU-2020.12.07.zip
a402c40717cd185ea8c14be2d4dc7df67580f197d276ae660a7cf478ae3e07e469c78271feb0c4c6b7c1c418bfb10e7f42c1e5f4b9635a4d3c47e1af4a747a4c  hunspell-en_GB-large-2020.12.07.zip
09f4ff19e628cb58bc43a62fd39bb9be88ef0e0d262d2462b44db15d0f4a222aa74d5a1798aed13260eb874ff6be9cd7a2f21f5fd96ba9b27c26a9432253d0a8  apostrophe.patch
"
